<template>
  <div>
    <template v-for="item in this.menuList">
      <!-- 当有chirden 节点的时候才进行遍历 -->
      <el-submenu
        :disabled="item.disabled"
        :index="item.id + ''"
        :key="item.id + ''"
        v-if="item.children.length > 0"
      >
        <template slot="title">
          <i :class="item.icon"></i>
          <span slot="title">{{ item.menuName }}</span>
        </template>
        <MenuTree :menuList="item.children"></MenuTree>
      </el-submenu>
      <!-- 没有chirden的时候遍历 el-menu-item -->
      <el-menu-item
        v-else
        :disabled="item.disabled"
        :index="item.id + ''"
        :key="item.id + ''"
        :route="item.url + ''"
        @click="savePath(item.url)"
      >
        <i :class="item.icon"></i>
        <span slot="title">{{ item.menuName }}</span>
      </el-menu-item>
    </template>
  </div>
</template>

<script>
export default {
  name: "MenuTree",
  props: ["menuList"],
  data() {
    return {};
  },
  methods: {
    // 保存激活路径
    savePath(url) {
      window.sessionStorage.setItem("activePath", url);
      // 调用Main,vue的激活路径
      this.activatePath = url;
    },
  },
};
</script>

<style>
</style>